package com.faxsun.core.persist.dao.impl;

import java.util.List;





import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import mtons.modules.persist.impl.DaoImpl;
import mtons.modules.pojos.Page;

import com.faxsun.core.persist.dao.WeChatMsgDao;
import com.faxsun.core.persist.entity.WechatMsgPO;

public class WeChatMsgDaoImpl extends DaoImpl<WechatMsgPO> implements WeChatMsgDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2498977616045100304L;

	protected WeChatMsgDaoImpl() {
		super(WechatMsgPO.class);
	}

	@Override
	public List<WechatMsgPO> listRecent(Page page, String topic) {
		TopQuery<WechatMsgPO> query = this.topQuery(page.getMaxResults());
		query.add(Restrictions.eq("topic", topic));
		query.desc("createTime");
		List<WechatMsgPO> ret = query.list();
		page.setResults(ret);
		return ret;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<WechatMsgPO> listPage(Page page, String topic){
		Criteria criteria = this.createCriteria();
		criteria.setFirstResult(page.getFirstResult());
		criteria.setMaxResults(page.getMaxResults());
		criteria.addOrder(Order.desc("createTime"));
		criteria.add(Restrictions.eq("topic", topic));
		
		List<WechatMsgPO> ret = criteria.list();
		page.setResults(ret);
		return ret;
	}

}
